package base_class

import (
	"encoding/xml"
	"fmt"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"log"
)

const timeFormat = "2006-01-02 03:04:05"

type BucketInfo struct {
	Location string
	CreateDate string
	ACL string
	Owner oss.Owner
	StorageClass string
	RedundancyType string
	ExtranetEndpoint string
	IntranetEndpoint string
}

func CreateBucketInfo(result oss.GetBucketInfoResult) (bucket *BucketInfo){
	return &BucketInfo{
		Location:        	result.BucketInfo.Location,
		CreateDate:      	result.BucketInfo.CreationDate.Format(timeFormat),
		ACL:             	result.BucketInfo.ACL,
		Owner:            	result.BucketInfo.Owner,
		StorageClass:     	result.BucketInfo.StorageClass,
		RedundancyType:    	result.BucketInfo.RedundancyType,
		ExtranetEndpoint: 	result.BucketInfo.ExtranetEndpoint,
		IntranetEndpoint:  	result.BucketInfo.IntranetEndpoint,
	}
}

func (b *BucketInfo)ToString () string {
	owner, err := xml.Marshal(b.Owner)
	if err != nil {
		log.Println(err)
		return ""
	}
	str := fmt.Sprintf("Location: %s, CreateDate: %s, ACL:%s, Owner:%s, StorageClass:%s, RedundancyType:%s, ExtranetEndpoint:%s, IntranetEndpoint:%s",
						b.Location, b.CreateDate, b.ACL, owner, b.StorageClass, b.RedundancyType, b.ExtranetEndpoint, b.IntranetEndpoint)
	return str
}
